<?php 

	if ($section != "comments") {
		if ($action == "add") { 
		$insertSQL = sprintf("INSERT INTO course_project (cid, vid, project_desc1) VALUES (%s, %s, %s)", 
			GetSQLValueString($cid, "int"),
			GetSQLValueString($_POST['vid'], "int"),
			GetSQLValueString($_POST['project_desc1'], "text")
		);
  		//echo $insertSQL;				
		mysql_select_db($database, $connection);
  		$result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
		
		$query_id_check = sprintf("SELECT id FROM %s WHERE cid='%s' AND vid='%s'", $dbTable, $cid, $_POST['vid']);
		$id_check = mysql_query($query_id_check, $connection) or die(mysql_error());
		$row_id_check = mysql_fetch_assoc($id_check);
		
		//echo $query_id_check."<br>";
		//echo $row_id_check['id'];
		
		if (($section != "comments") && ($_POST['project_desc1'] == "")) {
			header("location:../index.php?section=".$section."&action=edit&dbTable=".$dbTable."&cid=".$cid."&vid=".$_POST['vid']."&id=".$row_id_check['id']."&go=missing&msg=2"); 
			}
		else 
			{
			$insertGoTo = "../index.php?section=cpd&action=confirm&cid=".$cid."&vid=".$_POST['vid']."&id=".$row_id_check['id']."&msg=1";
			if (($section == "admin") && ($action == "edit")) $insertGoTo = "../index.php?section=list&msg=2";
			$insertGoTo = $insertGoTo."&msg=4";
			header(sprintf("Location: %s", $insertGoTo));
			}
		
		}
		
		if ($action == "edit") { 
		$updateSQL = sprintf("UPDATE course_project SET cid=%s, vid=%s, project_desc1=%s WHERE id=%s", 
			GetSQLValueString($cid, "int"),
			GetSQLValueString($_POST['vid'], "int"),
			GetSQLValueString($_POST['project_desc1'], "text"),
			GetSQLValueString($id, "int")
		);
  						
		mysql_select_db($database, $connection);
  		$result1 = mysql_query($updateSQL, $connection) or die(mysql_error());
		
		$query_id_check = sprintf("SELECT id FROM %s WHERE cid='%s' AND vid='%s'", $dbTable, $cid, $vid);
		$id_check = mysql_query($query_id_check, $connection) or die(mysql_error());
		$row_id_check = mysql_fetch_assoc($id_check);
		
		if (($section != "comments") && ($_POST['project_desc1'] == "")) {
			header("location:../index.php?section=".$section."&action=edit&dbTable=".$dbTable."&cid=".$cid."&vid=".$_POST['vid']."&id=".$row_id_check['id']."&go=missing&msg=2"); 
			}
		else 
			{
			if (($go == "no") || ($go == "missing")) $updateGoTo = "../index.php?section=cpd&action=confirm&cid=".$cid."&vid=".$_POST['vid']."&id=".$id."&msg=1&modal_window=".$modal_window;
			elseif ($go == "detail") $updateGoTo = "../index.php?section=view_proposal&dbTable=".$dbTable."&cid=".$cid."&vid=".$_POST['vid']."&id=".$row_id_check['id']."&msg=1&modal_window=".$modal_window;
			elseif ($go == "review") $updateGoTo = "../index.php?section=proposal_reveiw&cid=".$cid."&msg=1&modal_window=".$modal_window;
			//elseif $updateGoTo = "../index.php?section=proj_deliv&action=add&cid=".$cid."&msg=1";
			else $updateGoTo = $updateGoTo."&msg=5&modal_window=".$modal_window;
			//if ($section == "admin") $insertGoTo = "../index.php?section=list&msg=2";
			header(sprintf("Location: %s", $updateGoTo));
			}
		}
	}

?>